<?php
session_start(); 
include "config.php";

if ($_COOKIE['ck'] != COOKIEKEY) { header("location: login.php"); }

if ($_GET['x'] AND $_GET['f']) {
	force_download(base64_decode($_GET['f']));
} else {

	if (SHOWPATH == "yes") {
		echo "<p><strong>FOLDER: ".base64_decode($_GET['d'])."</strong></p>";
		$_SESSION['localDir'] = base64_decode($_GET['d']);		
	}
	echo "<table cellpadding=\"0\" border=\"0\" cellspacing=\"0\" width=\"100%\">";
	echo "
    	<thead>
	  <tr class=\"graylabel\">
		<td nowrap=\"nowrap\" style=\"width:10px;\">&nbsp;</td>
		<td nowrap=\"nowrap\"><a href=\"#\" onclick=\"return sortTable('TBOcustomerBrowse',1);\" class=\"sortlink\" title=\"Click to sort\">Name</a></td>
		<td nowrap=\"nowrap\"><a href=\"#\" onclick=\"return sortTable('TBOcustomerBrowse',2);\" class=\"sortlink\" title=\"Click to sort\">Size</a></td>
		<td nowrap=\"nowrap\"><a href=\"#\" onclick=\"return sortTable('TBOcustomerBrowse',3);\" class=\"sortlink\" title=\"Click to sort\">Type</a></td>
		
		<td nowrap=\"nowrap\" style=\"width:10px;\">&nbsp;</td>
	</tr>
	  </thead>
	  <tbody id=\"TBOcustomerBrowse\">
	";
	$files = getFiles(base64_decode($_GET['d']));

	$cellno = 1;
	foreach ($files as $file) {
			$mycell = "trcell".$cellno;
			if(eregi("[.]exe", $file[name])) {
				   $ext="exe";
				 } elseif(eregi("([.]php)|([.]asp)|([.]aspx)|([.]pl)|([.]cgi))", $file[name])) {
				   $ext="script";
				 } elseif(eregi("[.]doc", $file[name])) {
				   $ext="word";
				 } elseif(eregi("[.]xls", $file[name])) {
				   $ext="excel";
				 } elseif(eregi("[.]pdf", $file[name])) {
				   $ext="pdf";
				 } elseif(eregi("[.]ppt", $file[name])) {
				   $ext="powerpoint";
				 } elseif(eregi("([.]zip)|([.]rar)", $file[name])) {
				   $ext="archive";
				 } elseif(eregi("([.]gif)|([.]jpg)|([.]jpeg)|([.]png)|([.]bmp)", $file[name])) {
				   $ext="image";
				 } elseif(eregi("([.]html)|([.]htm)", $file[name])) {
				   $ext="html";
				 } elseif(eregi("([.]txt)|([.]css)|([.]tsv)|([.]csv)|([.]js)", $file[name])) {
				   $ext="text";
				 } else {
				   $ext="file";
			}
			$myfpath = base64_encode(base64_decode($_GET['d'])."/".$file[name].":");

			echo "<tr id=\"$mycell\" onMouseover=\"if (oncell != '$mycell') {overm('$mycell');}\" onMouseout=\"if (oncell != '$mycell') {outm('$mycell');}\"><td><img src=\"img/page.gif\" alt=\"$file[name]\" style=\"width:18px;height:18px; border:0px none;\" /></td><td nowrap=\"nowrap\"><a href=\"loadfiles.php?x=".$_GET['d']."&amp;f=".base64_encode($file[name])."\">".chopstring($file[name],FILENAMEMAXLENGTH,'')."</a></td><td>".sizeformat($file[size])."</td><td>$ext</td><td><a href=\"javascript:mylist('$myfpath','".$myfpath."')\"><img src=\"img/nolines_plus.gif\" alt=\"Add to my list: $file[name]\" style=\"width:18px;height:18px; border:0px none;\" /></a></td></tr>\n";
			$cellno++;
	}
	echo "</tbody></table>";

	$dsize = getDirectorySize(base64_decode($_GET['d']));

	echo "<p>$dsize[count] Files (Size: ".sizeformat($dsize[size]).")<p>";
}

?>